package com.job.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.job.dao.OfferDao;
import com.job.pojo.Check;
import com.job.pojo.Money;
import com.job.pojo.Offer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class OfferServiceImpl implements OfferService {
    @Autowired(required = false)
    OfferDao offerDao;

    @Override
    public HashMap<String, Object> select(Offer offer)
    {

        HashMap<String,Object>map=new HashMap<>();
        List<Offer> list=new ArrayList<>();
        if(offer.getUserName()!="")
        {
            list=offerDao.selectName(offer);
        }else
        {
            if(offer.getSex()!=""&&offer.getOfferTime()=="")
            {
                list=offerDao.selectSex(offer);
            }
            if(offer.getSex()==""&&offer.getOfferTime()!="")
            {
                list=offerDao.selectTime(offer);
            }
            if(offer.getSex()!=""&&offer.getOfferTime()!="")
            {
                list=offerDao.selectSexTime(offer);
            }
            if(offer.getSex()==""&&offer.getOfferTime()=="")
            {
                list=offerDao.selectAll();
            }
        }

        PageHelper.startPage(offer.getPage(),offer.getRow());
        PageInfo<Offer> page=new PageInfo<Offer>(list);

        //取出分页对象中的值
        // 当前页集合
        map.put("list",page.getList());
        //总条数
        map.put("total",page.getTotal());
        //总页数
        map.put("totalPage",page.getPages());
        //上一页

        if(page.getPrePage()==0){
            map.put("pre",1);
        }else{
            map.put("pre",page.getPrePage());
        }

        //下一页
        //保持在最后一页
        if(page.getNextPage()==0){
            map.put("next",page.getPages());
        }else{
            map.put("next",page.getNextPage());
        }
        //当前页
        map.put("cur",page.getPageNum());
        return map;
    }


    public List<Offer> time() {
        return offerDao.time();
    }



    //修改：
    @Override
    public String update(Offer offer) {


        int n=offerDao.update(offer);
        if(n>0)
        {
            return "成功";
        }return "失败";
    }

    //增加工资条：
    @Override
    public String add(Offer offer) {



        int n=offerDao.add(offer);
        if(n>0)
        {
            return "成功";
        }return "失败";
    }

    //删除
    @Override
    public String del(Offer offer) {
        int n=offerDao.del(offer);
        if(n>0)
        {
            return "删除成功";
        }else {
            return "删除失败";
        }
    }

    //查询笔试/面试
   @Override
    public List<Offer>pass(Offer offer)
   {

       List<Offer>list=new ArrayList<>();
       list=offerDao.pass(offer);

       return list;
   }

}
